<template>
   <div class="bottom-navigation">
      <div class="nav-item" :class="{ active: activeTab === 'home' }" @click="navigateTo('home')">
        <div class="nav-icon">
          <img :src="activeTab === 'home' ? homeIconActive : homeIcon" alt="home" />
        </div>
        <span class="nav-text" :class="{ active: activeTab === 'home' }">首页</span>
      </div>
      
      <div class="nav-item" :class="{ active: activeTab === 'file' }" @click="navigateTo('file')">
        <div class="nav-icon">
          <img :src="activeTab === 'file' ? fileIconActive : fileIcon" alt="file" />
        </div>
        <span class="nav-text" :class="{ active: activeTab === 'file' }">文件</span>
      </div>
    </div>
</template>

<script setup lang='ts'>
import { ref, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import homeIcon from '@/assets/images/nav/home.png';
import homeIconActive from '@/assets/images/nav/home_active.png';
import fileIcon from '@/assets/images/nav/file.png';
import fileIconActive from '@/assets/images/nav/file_active.png';

const route = useRoute()
const router = useRouter()

// 根据当前路由计算激活的标签
const activeTab = computed(() => {
  if (route.path === '/file') {
    return 'file'
  }
  return 'home'
})

const navigateTo = (tab: string) => {
  console.log(tab)
  // 路由跳转逻辑
  if(tab === 'home') {
    router.push({ path: '/' })
  } else {
    router.push({ path: '/file' })
  }
}

</script>

<style lang='scss' scoped>
.bottom-navigation {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: #fff;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 15px 0;
  cursor: pointer;
  transition: all 0.3s ease;
  
  &:hover {
    background-color: #f8f9fa;
  }
}

.nav-icon {
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-text {
  font-size: 12px;
  color: #999;
  transition: color 0.3s ease;
  
  &.active {
    color: #338af4;
  }
}

.nav-item.active .nav-text {
  color: #338af4;
}
</style>